import 'package:flutter/material.dart';
// 全局进度条
class LoadingContainer extends StatelessWidget {
  final Widget child;// 进度条加载完毕后显示的组件
  final bool isLoading;// true 表示正在加载
  final bool cover;// true 进度条以覆盖整个页面的形式显示
  const LoadingContainer({super.key, required this.child, required this.isLoading, required this.cover});

  get _loadingView => const Center(
    child: CircularProgressIndicator(color: Colors.blue,),
  );

  get _coverView => Stack(//  cover = true 则将进度条覆盖到当前页面上面（叠加效果）
    children: [child, isLoading ? _loadingView : Container()],
  );

  get _normalView => isLoading ? _loadingView : child;

  @override
  Widget build(BuildContext context) {
    return cover ?  _coverView : _normalView;
  }
}
